package com.bdqn.t382.Service;

import com.bdqn.t382.dao.SysUserMapper;
import com.bdqn.t382.entity.SysUser;

import java.util.List;

public class SysUserServiceImpl implements SysUserService {

 private SysUserMapper sysUserMapper;

    @Override
    public List<SysUser> findList(SysUser sysUser) {
        return sysUserMapper.getSysUserList(sysUser);
    }

    @Override
 public int saveBatch(List<SysUser> sysUserList) {
        int rows = 0;
        for (int i = 0; i < sysUserList.size(); i++) {
            // 拿出每一条用户数据插入
             SysUser sysUser = sysUserList.get(i);
             if(i == 1){
                 // 插入第二条数据时，模拟数据库异常，查看事务是否生效
                 throw new RuntimeException("数据库异常");
                 }
             // 调用插入数据操作，计入总受影响行数
             rows += sysUserMapper.insert(sysUser);
             }
         // 返回总受影响行数
         return rows;
         }
}
